package com.zfei.gfb.core;

import java.util.Properties;

/**
 * @author fgh
 */
public class Conf {

    private static final Properties PROPERTIES = System.getProperties();

    public static Properties getProperties() {
        return PROPERTIES;
    }

    public static Integer getInteger(String key, Integer defaultValue) {
        try {
            String value = getProperties().getProperty(key);
            return value == null ? defaultValue : Integer.valueOf(value);
        } catch (Exception e) {
            return defaultValue;
        }
    }

    public static Integer getInteger(String key) {
        return getInteger(key, null);
    }

    public static void setInteger(String key, Integer value) {
        getProperties().setProperty(key, value.toString());
    }

    public static Long getLong(String key, Long defaultValue) {
        try {
            String value = getProperties().getProperty(key);
            return value == null ? defaultValue : Long.valueOf(value);
        } catch (Exception e) {
            return defaultValue;
        }
    }

    public static Long getLong(String key) {
        return getLong(key, null);
    }

    public static void setLong(String key, Long value) {
        getProperties().setProperty(key, value.toString());
    }

    public static Double getDouble(String key, Double defaultValue) {
        try {
            String value = getProperties().getProperty(key);
            return value == null ? defaultValue : Double.valueOf(value);
        } catch (Exception e) {
            return defaultValue;
        }
    }

    public static Double getDouble(String key) {
        return getDouble(key, null);
    }

    public static void setDouble(String key, Double value) {
        getProperties().setProperty(key, value.toString());
    }

    public static String getString(String key, String defaultValue) {
        return getProperties().getProperty(key, defaultValue);
    }

    public static String getString(String key) {
        return getString(key, null);
    }

    public static void setString(String key, String value) {
        getProperties().setProperty(key, value);
    }

    public static Boolean getBoolean(String key, Boolean defaultValue) {
        String value = getProperties().getProperty(key);
        return value == null ? defaultValue : Boolean.valueOf(value);
    }

    public static Boolean getBoolean(String key) {
        return getBoolean(key, null);
    }

    public static void setBoolean(String key, Boolean value) {
        getProperties().setProperty(key, value.toString());
    }
}